import type { ResponseData } from '@/utils/request';
import { SUCCESS_CODE } from '@/utils/request';
import type { RequestData } from '@ant-design/pro-table';
import { message } from 'antd';
import { request } from 'umi';
import type {
  createParkItem,
  Has_exists,
  imageList,
  ParkItem,
  QueryParams,
  updateParkItem,
} from './types';

//查询单个数据
export async function getParkDetail(id: string) {
  return await request(`/zone/zone/${id}`);
}

//停车场列表
export async function getParkTable(params: QueryParams): Promise<RequestData<ParkItem>> {
  return await request('/zone/zone/list', {
    params: {
      page: params.current,
      pageSize: params.pageSize,
      name: params.name,
      type: params.type,
      tenant_id: params.tenant ? params.tenant?.id : '',
    },
  });
}

//删除停车场
export async function deletePark(params: { id: string }): Promise<ResponseData<ParkItem>> {
  return await request(`/zone/zone/${params.id}`, {
    method: 'DELETE',
  });
}

//添加停车场
export async function addParkItem(params: createParkItem): Promise<ResponseData<ParkItem>> {
  return await request('/zone/zone/add', {
    method: 'POST',
    data: {
      ...params,
      // space_total_count: params.space_total_count || 0,
      lat: Number(params.location?.[1]),
      lng: Number(params.location?.[0]),
      scheme_id: params.scheme?.id,
      tenant_id: params.tenant?.id,
      reserve_scheme_id: params.reserve_scheme?.id,
    },
  });
}
